﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AccesoDatos;
using AccesoDatos.Manejador;

namespace RMA
{
    public partial class frmAlmacen : Form
    {
        Manejador_Embarque manEm = new Manejador_Embarque();
        string EmbarqueId;

        public frmAlmacen()
        {
            InitializeComponent();
        }

        private void frmAlmacen_Load(object sender, EventArgs e)
        {
            llenarDatos();
        }

        private void llenarDatos()
        {
            dgvAlmacen.DataSource = manEm.GetEmbarquesAlmacen();
            dgvAlmacen.Columns[0].Visible = false;
        }

        private void dgvAlmacen_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex != 0 && e.RowIndex >= 0)
            {
                try
                {
                    EmbarqueId = dgvAlmacen[0, e.RowIndex].Value.ToString();
                    lblNumero.Text = dgvAlmacen[1, e.RowIndex].Value.ToString();
                    btnConfirmar.Visible = true;
                }
                catch
                {

                }
            }
        }

        private void btnConfirmar_Click(object sender, EventArgs e)
        {
            pnlConfirmar.Visible = true;
            btnConfirmar.Visible = false;

        }

        private void btnCancelar_Click(object sender, EventArgs e)
        {
            pnlConfirmar.Visible = false;
            lblNumero.Text = "";
        }

        private void txtRecivido_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (Char.IsDigit(e.KeyChar))
            {
                e.Handled = false;
            }
            else if (Char.IsControl(e.KeyChar))
            {
                e.Handled = false;
            }
            else if (Char.IsSeparator(e.KeyChar))
            {
                e.Handled = false;
            }
            else if (Char.IsPunctuation(e.KeyChar))
            {
                e.Handled = false;
            }
            else
            {
                e.Handled = true;
            }
        }

        private void btnAceptar_Click(object sender, EventArgs e)
        {
            if (manEm.ConfirmarAlmacen(EmbarqueId, txtRecivido.Text))
            {
                llenarDatos();
                btnConfirmar.Visible = false;
                pnlConfirmar.Visible = false;
            }
            else 
            {
                MessageBox.Show("Ocurrio un Error", "Error");
            }
        }
    }
}
